<template>
  <el-container>
    <el-main>
      <div class="page-main-body-box">
        <div class="meedu-main-body">
          <div class="back-bar-box mb-30">
            <div class="btn-back" @click="goBack">
              <i class="el-icon-back"></i> 返回
            </div>
            <div class="line"></div>
            <div class="name">课时批量导入</div>
          </div>
          <div class="user-import-box">
            <div class="float-left d-flex mb-15">
              <el-button type="primary" @click.stop="importTable"
                >导入表格</el-button
              >
              <el-link type="primary" class="ml-30"
                >下载「课时批量导入模板」</el-link
              >
            </div>
            <div class="float-left">
              <div style="display: none">
                <form ref="form">
                  <input type="file" ref="xlsfile" />
                </form>
              </div>
            </div>
          </div>
        </div>
      </div>
    </el-main>
    <!-- <el-footer>Footer</el-footer> -->
  </el-container>
</template>

<script>
import { login } from "@/network/user";
// import XLSX from "xlsx";
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';

export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {};
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    goBack: function () {
      this.$router.go(-1);
    },
    importTable() {
      // 得到元素，调用点击事件
      this.$refs.xlsfile.click();
    },
    handleFile: function (e) {
      // 一个数组
      let file = e.target.files;
      if (file.length === 0) {
        this.$message.error("请选择文件");
        return;
      }
      let f = file[0];
      let extension = f.name.split(".");
      extension = extension[extension.length - 1];
      if (extension !== "xlsx") {
        this.$message.error("请选择xlsx文件");
        return;
      }
      // 读取文件
      // let reader = new FileReader();
      // console.log(reader);
      // // 读取成功时调用onload
      // reader.onload=(e)=>{
      //   console.log(e);
      // }
      // reader.onerror=function(){
      //   console.log("读取失败");
      // }
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.$nextTick(() => {
      this.$refs.xlsfile.addEventListener("change", this.handleFile, false);
    });
  },
};
</script>
<style lang="scss" scoped>
.el-container {
  height: 100%;
  text-align: center;
}
.el-main {
  background-color: #f1f2f9;
  // line-height: 200px;
  .page-main-body-box {
    flex: 1;
    height: 100%;
    box-sizing: border-box;
    padding: 20px 5px 20px 20px;
    overflow-y: auto;
    background-color: #f1f2f9;
    .meedu-main-body {
      width: 100%;
      height: auto;
      float: left;
      background-color: #fff;
      box-sizing: border-box;
      padding: 30px;
      border-radius: 15px;
      margin-bottom: 90px;
      box-shadow: 0 2px 4px 0 hsl(0deg 0% 40% / 5%);
      min-width: 1180px;
      .back-bar-box.mb-30 {
        width: 100%;
        height: auto;
        float: left;
        margin-bottom: 30px;
        display: flex;
        align-items: center;
        .btn-back {
          font-size: 14px;
          font-weight: 400;
          color: #333;
          cursor: pointer;
          i.el-icon-back {
            font-family: element-icons !important;
            // speak: none;
            font-style: normal;
            font-weight: 400;
            font-variant: normal;
            text-transform: none;
            line-height: 1;
            vertical-align: baseline;
            display: inline-block;
            -webkit-font-smoothing: antialiased;
          }
        }

        .line {
          width: 1px;
          height: 14px;
          background-color: #d8d8d8;
          margin-right: 15px;
          margin-left: 15px;
        }

        .name {
          font-size: 14px;
          font-weight: 600;
          color: #333;
        }
      }

      .user-import-box {
        width: 100%;
        height: auto;
        float: left;
        box-sizing: border-box;
        padding: 30px 100px;
        border-radius: 15px;
        background-color: #fff;
        .float-left.d-flex.mb-15 {
          display: flex;
          align-items: center;
          margin-bottom: 15px;
          width: 100%;
          height: auto;
          float: left;
          // el-button {
          // }

          .ml-30 {
            margin-left: 30px;
            .el-link.el-link--primary {
              font-weight: 400;
            }
          }
        }

        .float-left {
          width: 100%;
          height: auto;
          float: left;
          text-align: left;
          div {
            display: none;
            // form {
            //   input {
            //   }
            // }
          }
        }
      }
    }
  }
}
.el-footer {
  background-color: #f1f2f9;
}
</style>